#include <msg_flight_data_s.hpp>
#include <msg_param_s.hpp>
#include <remote_controller_tcp.hpp>

TcpServerClient* RemoteControllerTcp::RemoteControllerTcpCreator()
{
	return new RemoteControllerTcp();
}

RemoteControllerTcp::RemoteControllerTcp()
	: m_DataSeqRecv(0)
	, m_DataTypeRecv(0)
	, m_SizeRecv(0)
{
	m_BuffRecv = (char*)malloc(BUFF_FIFO_SIZE);
}

RemoteControllerTcp::~RemoteControllerTcp()
{
	free(m_BuffRecv);
}

void RemoteControllerTcp::RecvData(char* data, int size)
{
	if (size <= 0)
	{
		return;
	}

#if 0
	printf("recv %d:\n", size);
	for (int i = 0; i < size; i++)
	{
		printf("%02x ", (uint8_t)data[i]);
	}
	printf("\n");
#endif

	m_BuffFifo.Append(data, size);
	while (1)
	{
		if (m_Protocol.Unpack(m_BuffRecv, &m_SizeRecv, &m_DataSeqRecv, &m_DataTypeRecv, &m_BuffFifo) != 0)
		{
			break;
		}

		switch (m_DataTypeRecv)
		{
			case P_TYPE_HEART:
				break;

			default:
				break;
		}
	}
}